package kr.co.sdsway2.common;

import org.apache.log4j.Logger;

public abstract class AbstractCommon {
	private Logger log = Logger.getLogger(this.getClass());
	
	private boolean methodPrint = true;
	
	public void setMethodPrint(boolean printEnable) {
		this.methodPrint = printEnable;
	}

	public void debug(Object msg) {
		log.debug(getMethodName() + " " + msg);
	}

	public void info(Object msg) {
		log.info(getMethodName() + " " + msg);
	}

	public void warn(Object msg) {
		log.warn(getMethodName() + " " + msg);
	}

	public void error(Object msg) {
		log.error(getMethodName() + " " + msg);
	}

	public void fatal(Object msg) {
		log.fatal(getMethodName() + " " + msg);
	}

	private Object getMethodName() {
		if(methodPrint) {
			Exception e = new Exception();
			StackTraceElement[] stackTrace = e.getStackTrace();
			if(stackTrace!=null && stackTrace.length>2) {
				return "[" + stackTrace[2].getMethodName() + "]";
			}
		}
		return "";
	}
	
}
